package cn.glutnn.controller;


import cn.glutnn.entity.OrderDetail;
import cn.glutnn.entity.Result;
import cn.glutnn.service.OrderDetailService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * 订单明细表(OrderDetail)表控制层
 *
 * @author msh
 * @since 2024-12-12 16:54:36
 */
@RestController
@RequestMapping("/orderDetail")
public class OrderDetailController {
    /**
     * 服务对象
     */
    @Autowired
    private OrderDetailService orderDetailService;

    @GetMapping("/list")
    public Result<List<OrderDetail>> list() {
        return Result.success(orderDetailService.list());
    }

    @GetMapping("/{id}")
    public Result<OrderDetail> getById(@PathVariable Serializable id) {
        return Result.success(orderDetailService.getById(id));
    }

    @PostMapping
    public Result<String> save(@RequestBody OrderDetail orderDetail) {
        orderDetailService.save(orderDetail);
        return Result.success("添加成功");
    }

    // 根据订单id查询订单详情
    @GetMapping("/listOrderDetailByOrderId/{orderId}")
    public Result<List<OrderDetail>> listOrderDetailByOrderId(@PathVariable Integer orderId) {
        LambdaQueryWrapper<OrderDetail> wrapper = new LambdaQueryWrapper<OrderDetail>().eq(OrderDetail::getOrderId, orderId);
        return Result.success(orderDetailService.list(wrapper));
    }
}

